
	// $(document).ready(function(){
	// 	console.log(localStorage.session);
	// 	if(localStorage.session){
	// 		window.location.href = window.location.href + "homepage.html";
	// 	}
	// });

	function login(){
		if(window.event.keyCode === 13){
			checkAndlogin();
		}
	}

	function checkAndlogin(){
			var inputData = document.getElementsByTagName('input'),
					usernameMess = document.getElementById('usernameMess'),
					passwordMess = document.getElementById('passwordMess');
			var reg = /^([a-zA-Z0-9]{8,16})$/;
			if(!reg.test(inputData[0].value)){
				usernameMess.style.display = 'block';
			}else{
				usernameMess.style.display = 'none';
			}
			var obj = {
				username:inputData[0].value,
				password:inputData[1].value
			};
			var level;
			request(obj,'account/login',function(data){
					var loginStatus = data.status;
					if(loginStatus === 0 ){
						localStorage.session = data.data.session;
						localStorage.userLevel = data.data.level;
						level = data.data.level;
						var el = {};
						el.username = obj.username;
						requestWithSession(el,hostUrl + '/account/getuserinfo',function(data){
							if(data){
								if(data.status == 0){
									if(!data.data.realname){
										alert('请先完成个人信息设置！');
										window.location.href = window.location.href + "setting.html";
									}else {
										localStorage.realName = data.data.realname;
										if(level == 1 || level == 2){
											window.location.href = window.location.href + "homepage.html";
										}else if (level == 3) {
											window.location.href = window.location.href + "personnalManagement.html";
										}
									}
								}
							}
						},function(error){
							console.log(error);
						});
					}else{
						alert(data.message);
						passwordMess.style.display = 'block';
					}
			},
			function(error){
				alert(error.responseText);
			});
	};
